--[[
卡片显示 
]]

local LevelInfoSprite =  require("app.views.editor.LevelInfoSprite")
local CardListSprite =  require("app.views.editor.CardListSprite")
local CardInfoSprite =  require("app.views.editor.CardInfoSprite")
local LevelDump =  require("app.views.editor.LevelDump")
local CardEditorView = class("CardEditorView", BaseSprite)




function CardEditorView:initView()
    local bg = display.newSprite("#EditorPanelBg.png")
    --local size = bg:getContentSize()
    --bg:align(display.LEFT_TOP, 0, 0)
    bg:align(display.BOTTOM_LEFT, 0, 0)
    --bg:getTexture():setAliasTexParameters()
    self:addChild(bg)
    
  
  	
    
    --list信息
	self.CardListSprite_ = CardListSprite.new(nil,self);
	self.CardListSprite_:initView();
	self:addChild(self.CardListSprite_);
	self.CardListSprite_:align(display.BOTTOM_LEFT, 0, 0)
	
	
	
	--详细信息描述
    self.CardInfoSprite_ = CardInfoSprite.new(nil,self);
	self.CardInfoSprite_:initView();
	self:addChild(self.CardInfoSprite_);
	self.CardInfoSprite_:align(display.BOTTOM_LEFT, 0, 60)
	
    
    --关卡详细信息描述
    self.LevelInfoSprite_ = LevelInfoSprite.new(nil,self);
	self.LevelInfoSprite_:initView();
	self:addChild(self.LevelInfoSprite_);
	self.LevelInfoSprite_:align(display.BOTTOM_LEFT, 0, 160)
    
	  
	local  boundingBox= self:getCascadeBoundingBox();
	local size = boundingBox.size --self.CardListSprite_:getContentSize();
	local origin = boundingBox.origin
	local bgSize = bg:getContentSize()
	bg:setScaleX(size.width/bgSize.width);
	bg:setScaleY(size.height/bgSize.height);
	
	
	
    --关闭按钮
    local closeButton = display.newSprite("#EditorPanelCloseButton.png")
    --closeButton:setPosition(size.width,size.height)
    closeButton:align(display.TOP_RIGHT, size.width,size.height - 10)
    self:addChild(closeButton)
    closeButton:setTouchEnabled(true)
    closeButton:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE) --单点 TOUCH_MODE_ALL_AT_ONCE多点
    closeButton:setTouchSwallowEnabled(true) -- 是否吞噬事件，默认值为 true
    closeButton:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
       self:close(event);
       return true;
    end)
    
    
    --保存按钮
     local SaveMapButton = display.newSprite("#SaveMapButton.png")
    --closeButton:setPosition(size.width,size.height)
    SaveMapButton:align(display.TOP_RIGHT, size.width-30,size.height)
    self:addChild(SaveMapButton)
    SaveMapButton:setTouchEnabled(true)
    SaveMapButton:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE) --单点 TOUCH_MODE_ALL_AT_ONCE多点
    SaveMapButton:setTouchSwallowEnabled(true) -- 是否吞噬事件，默认值为 true
    SaveMapButton:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
       self:save(event);
       return true;
    end)
    
end




function CardEditorView:updateView(targetCard)
	self:setVisible(true);
	
	self.CardListSprite_:updateView(targetCard);
	self.CardInfoSprite_:updateView(targetCard);
	self.LevelInfoSprite_:updateView(targetCard);
	
end

--关闭
function CardEditorView:close(event)
    if event.name == "ended" then
    	self:setVisible(false);
    end
end
--保存
function CardEditorView:save(event)
    if event.name == "ended" then
    	
		local EditorController = require("app.controllers.EditorController")
    	LevelDump.dumpToFile(EditorController.getInstance().model_)
    end
end



return CardEditorView
